package food;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import java.io.IOException;

public class MyRecordWriter extends RecordWriter<food, NullWritable> {
    FSDataOutputStream stream;
    public MyRecordWriter(TaskAttemptContext taskAttemptContext) throws IOException{
        FileSystem fs = FileSystem.get(taskAttemptContext.getConfiguration());
        stream = fs.create(new Path("D:\\MP\\food\\result.csv"));
    }
    public void write(food key, NullWritable value) throws IOException, InterruptedException {
        stream.write(key.toString().getBytes());
        stream.write("\n".getBytes());
    }

    public void close(TaskAttemptContext context) throws IOException, InterruptedException {
        stream.close();
    }
}
